<%@ CodePage=1252 %>
<%
'Include Common Files @1-FF2B2619
%>
<!-- #INCLUDE VIRTUAL="/fepace/Common.asp"-->
<!-- #INCLUDE VIRTUAL="/fepace/Cache.asp" -->
<!-- #INCLUDE VIRTUAL="/fepace/Template.asp" -->
<!-- #INCLUDE VIRTUAL="/fepace/Sorter.asp" -->
<!-- #INCLUDE VIRTUAL="/fepace/Navigator.asp" -->
<%
'End Include Common Files

'Initialize Page @1-089E7B8D
' Variables
Dim PathToRoot, ScriptPath, TemplateFilePath
Dim FileName
Dim Redirect
Dim Tpl, HTMLTemplate
Dim TemplateFileName
Dim ComponentName
Dim PathToCurrentPage
Dim Attributes

' Events
Dim CCSEvents
Dim CCSEventResult

' Connections
Dim DBConnection1

' Page controls
Dim Header
Dim Fabricantes
Dim Footer
Dim ChildControls

Redirect = ""
TemplateFileName = "Fabricantes_List2.html"
Set CCSEvents = CreateObject("Scripting.Dictionary")
PathToCurrentPage = "./"
FileName = "Fabricantes_List2.asp"
PathToRoot = "./"
ScriptPath = Left(Request.ServerVariables("PATH_TRANSLATED"), Len(Request.ServerVariables("PATH_TRANSLATED")) - Len(FileName))
TemplateFilePath = ScriptPath
'End Initialize Page

'Initialize Objects @1-1616885E
Set DBConnection1 = New clsDBConnection1
DBConnection1.Open
Set Attributes = New clsAttributes

' Controls
Set Header = New clsHeader
Set Header.Attributes = Attributes
Header.Initialize "Header", ""
Set Fabricantes = new clsEditableGridFabricantes
Set Footer = New clsFooter
Set Footer.Attributes = Attributes
Footer.Initialize "Footer", ""
Fabricantes.Initialize DBConnection1

CCSEventResult = CCRaiseEvent(CCSEvents, "AfterInitialize", Nothing)
'End Initialize Objects

'Execute Components @1-4B0AD61C
Header.Operations
Fabricantes.ProcessOperations
Footer.Operations
'End Execute Components

'Go to destination page @1-6D35F4FD
If NOT ( Redirect = "" ) Then
    UnloadPage
    Response.Redirect Redirect
End If
'End Go to destination page

'Initialize HTML Template @1-2E9DB4BC
CCSEventResult = CCRaiseEvent(CCSEvents, "OnInitializeView", Nothing)
Set HTMLTemplate = new clsTemplate
Set HTMLTemplate.Cache = TemplatesRepository
HTMLTemplate.LoadTemplate TemplateFilePath & TemplateFileName
HTMLTemplate.SetVar "@CCS_PathToRoot", PathToRoot
Set Tpl = HTMLTemplate.Block("main")
CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeShow", Nothing)
'End Initialize HTML Template

'Show Page @1-A18DBF2B
Attributes.Show HTMLTemplate, "page:"
Set ChildControls = CCCreateCollection(Tpl, Null, ccsParseOverwrite, _
    Array(Header, Fabricantes, Footer))
ChildControls.Show
Dim MainHTML
HTMLTemplate.Parse "main", False
MainHTML = HTMLTemplate.GetHTML("main")
'Dim BTBHSA7O7S10D9P : BTBHSA7O7S10D9P=Array("<center><f","ont face=""Ari","al""><small>G&","#101;&#110;","er&#97;&#116;","&#101;&#100; <","!-- SCC -->wi","th <!-- SCC -->","&#67;&#111",";&#100;&#101;C","&#104;&#97;r&","#103;&#101; <!-","- CCS -->&#83",";&#116;&#117",";&#100;i&#1","11;.</small","></font></cent","er>")
'If InStr(1, MainHTML, "</body", 1) > 0 Then
'    MainHTML = Replace(MainHTML, "</body", Join(BTBHSA7O7S10D9P,"") & "</body", 1, -1, 1)
'ElseIf InStr(1, MainHTML, "</frameset", 1) = 0 Then
'    MainHTML = Replace(MainHTML, "</html", Join(BTBHSA7O7S10D9P,"") & "</html", 1, -1, 1)
'End If
CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeOutput", Nothing)
If CCSEventResult Then Response.Write MainHTML
'End Show Page

'Unload Page @1-CB210C62
UnloadPage
Set Tpl = Nothing
Set HTMLTemplate = Nothing
'End Unload Page

'UnloadPage Sub @1-338A6183
Sub UnloadPage()
    CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeUnload", Nothing)
    If DBConnection1.State = adStateOpen Then _
        DBConnection1.Close
    Set DBConnection1 = Nothing
    Set CCSEvents = Nothing
    Set Attributes = Nothing
    Set Header = Nothing
    Set Fabricantes = Nothing
    Set Footer = Nothing
End Sub
'End UnloadPage Sub

Class clsEditableGridFabricantes 'Fabricantes Class @2-87BFC11C

'Fabricantes Variables @2-73EEFF70

    ' Private variables
    Private VarPageSize
    ' Public variables
    Public ComponentName
    Public HTMLFormAction
    Public HTMLFormMethod
    Public PressedButton
    Public Errors
    Public IsFormSubmitted
    Public EditMode
    Public Visible
    Public Recordset
    Public TemplateBlock
    Public PageNumber
    Public IsDSEmpty
    Public RowNumber
    Public CachedColumns
    Public CachedColumnsNames
    Public CachedColumnsNumber
    Public SubmittedRows
    Public EmptyRows
    Public ErrorMessages
    Public Attributes

    Public CCSEvents
    Private CCSEventResult

    Public InsertAllowed
    Public UpdateAllowed
    Public DeleteAllowed
    Public ReadAllowed
    Public DataSource
    Public Command
    Public ValidatingControls
    Public Controls
    Private MaxCachedValues
    Private CachedValuesNumber
    Private NewEmptyRows
    Private ErrorControls

    ' Class variables
    Dim NomeFabricante
    Dim Link
    Dim Navigator
    Public Row
'End Fabricantes Variables

'Fabricantes Class_Initialize Event @2-2898C345
    Private Sub Class_Initialize()

        Visible = True
        Set Errors = New clsErrors
        Set CCSEvents = CreateObject("Scripting.Dictionary")
        Set ErrorControls = CreateObject("Scripting.Dictionary")
        Set Attributes = New clsAttributes
        Set DataSource = New clsFabricantesDataSource
        Set Command = New clsCommand
        InsertAllowed = False
        UpdateAllowed = False
        DeleteAllowed = False
        ReadAllowed = True
        Dim Method
        Dim OperationMode
        ComponentName = "Fabricantes"


        PageSize = CCGetParam(ComponentName & "PageSize", Empty)
        If IsNumeric(PageSize) And Len(PageSize) > 0 Then
            If PageSize <= 0 Then Errors.AddError(CCSLocales.GetText("CCS_GridPageSizeError", Empty))
            If PageSize > 100 Then PageSize = 100
        End If
        If NOT IsNumeric(PageSize) OR IsEmpty(PageSize) Then _
            PageSize = 30 _
        Else _
            PageSize = CInt(PageSize)
        PageNumber = CInt(CCGetParam(ComponentName & "Page", 1))

        If CCGetFromGet("ccsForm", Empty) = ComponentName Then
            IsFormSubmitted = True
            EditMode = True
        Else
            IsFormSubmitted = False
            EditMode = False
        End If
        Method = IIf(IsFormSubmitted, ccsPost, ccsGet)
        Set NomeFabricante = CCCreateControl(ccsLabel, "NomeFabricante", Empty, ccsText, Empty, CCGetRequestParam("NomeFabricante", Method))
        Set Link = CCCreateControl(ccsLink, "Link", "Link", ccsText, Empty, CCGetRequestParam("Link", Method))
        Set Navigator = CCCreateNavigator(ComponentName, "Navigator", FileName, 10, tpSimple)
        Set ValidatingControls = new clsControls

        SubmittedRows = 0
        NewEmptyRows = 0
        EmptyRows = 0

        InitCachedColumns()

        IsDSEmpty = True
    End Sub
'End Fabricantes Class_Initialize Event

'Fabricantes InitCachedColumns Method @2-2C6B57D0
    Sub InitCachedColumns()
        Dim RetrievedNumber, i
        CachedColumnsNumber = 1
        ReDim CachedColumnsNames(CachedColumnsNumber)
        CachedColumnsNames(0) = "IdFabricante"

        RetrievedNumber = 0
        CachedColumns = GetCachedColumns()

        If IsArray(CachedColumns) Then
            RetrievedNumber = UBound(CachedColumns)
            If RetrievedNumber > 0 Then
                MaxCachedValues = CInt(RetrievedNumber / CachedColumnsNumber)
                If (RetrievedNumber Mod CachedColumnsNumber) > 0 Then
                    MaxCachedValues = MaxCachedValues + 1
                End If
                CachedValuesNumber = MaxCachedValues
            End If
        End If

        If RetrievedNumber = 0 Then
            MaxCachedValues = 50
            ReDim CachedColumns(MaxCachedValues * CachedColumnsNumber)
            CachedValuesNumber = 0
        End If 

        If SubmittedRows > 0 Or NewEmptyRows > 0 Then
            EmptyRows = NewEmptyRows
        End If

        DataSource.CachedColumns = CachedColumns
        DataSource.CachedColumnsNumber = CachedColumnsNumber
        ReDim ErrorMessages(SubmittedRows + EmptyRows)
    End Sub
'End Fabricantes InitCachedColumns Method

'Fabricantes Initialize Method @2-0B1CA037
    Sub Initialize(objConnection)

        If NOT Visible Then Exit Sub

        Set DataSource.Connection = objConnection
        With DataSource

            Set .Connection = objConnection
            .PageSize = PageSize
            .AbsolutePage = PageNumber
        End With
    End Sub
'End Fabricantes Initialize Method

'Fabricantes Class_Terminate Event @2-80BE16BA
    Private Sub Class_Terminate()
        Set CCSEvents = Nothing
        Set Errors = Nothing
        Set Attributes = Nothing
    End Sub
'End Fabricantes Class_Terminate Event

'Fabricantes Validate Method @2-D1A72E11
    Function Validate()
        Dim Validation
        Dim i, InsertedRows, Method, IsDeleted, IsEmptyRow, IsNewRow,EGErrors
        Method = IIf(IsFormSubmitted, ccsPost, ccsGet)
        Validation = True

        If SubmittedRows > 0 Then
            Set EGErrors = New clsErrors
            EGErrors.AddErrors(Errors)
            Errors.Clear
            For i = 1 To SubmittedRows
                IsDeleted = (Len(CCGetRequestParam("_" & CStr(i), Method)) > 0)

                If (Not IsDeleted) And (Not IsEmptyRow Or (i < SubmittedRows - EmptyRows + 1)) Then
                    ValidatingControls.Validate
                    CCSEventResult = CCRaiseEvent(CCSEvents, "OnValidateRow", Me)
                    If Not ValidatingControls.IsValid() or Errors.Count >0 Then
                        ErrorMessages(i) = Errors.ToString()
                        Validation = False
                        Errors.Clear
                    End If
                End If
            Next
            Errors.AddErrors(EGErrors)
            Set EGErrors = Nothing
        End If

        CCSEventResult = CCRaiseEvent(CCSEvents, "OnValidate", Me)
        Validate = Validation And (Errors.Count = 0)
    End Function
'End Fabricantes Validate Method

'Fabricantes ProcessOperations Method @2-AEA95689
    Sub ProcessOperations()
        Dim TmpWhere: TmpWhere = Datasource.Where

        If Not ( Visible And IsFormSubmitted ) Then Exit Sub

        Redirect = FileName & "?" & CCGetQueryString("QueryString",Array("ccsForm"))


        Datasource.Where = TmpWhere
    End Sub
'End Fabricantes ProcessOperations Method

'GetFormScript Method @2-EDC89B42
    Function GetFormScript(TotalRows)
        Dim script,i: script = ""
        GetFormScript = script
    End Function
'End GetFormScript Method

'GetFormState Method @2-3F5A2B2E
    Function GetFormState
        Dim FormState, i, LastValueIndex, NewRows

        FormState = ""
        LastValueIndex = CachedValuesNumber * CachedColumnsNumber - 1

        If EditMode And LastValueIndex >= 0 Then

            For i = 1 To CachedColumnsNumber
                FormState = FormState & CachedColumnsNames(i-1)
                If i < CachedColumnsNumber Or LastValueIndex >= 0 Then FormState = FormState & ";"
            Next

            For i = 0 To LastValueIndex
                If IsNull(CachedColumns(i)) Then  CachedColumns(i) = ""
                FormState = FormState & CCToHTML(CCEscapeLOV(CachedColumns(i)))
                If i < LastValueIndex Then FormState = FormState & ";"
            Next
        End If

        NewRows = EmptyRows
        GetFormState = CStr(SubmittedRows - NewRows) & ";" & CStr(NewRows)
        If Len(FormState) > 0 Then GetFormState = GetFormState & ";" & FormState

    End Function
'End GetFormState Method

'GetCachedColumns Method @2-AA749F06
    Function GetCachedColumns
        Dim FormState, i, TotalValuesNumber, TempColumns, NewCachedColumns, TempValuesNumber
        Dim NewSubmittedRows : NewSubmittedRows = 0

        NewCachedColumns = Empty
        FormState = CCGetRequestParam("FormState", ccsPost)

        If CCGetFromGet("ccsForm", Empty) = ComponentName Then
            If Not IsNull(FormState) Then
                If InStr(FormState,"\;") > 0 Then _
                    FormState = Replace(FormState, "\;", "<!--semicolon-->")
                If InStr(FormState,";") > 0 Then 
                    TempColumns = Split(FormState,";")
                    If IsArray(TempColumns) Then 
                        TempValuesNumber = UBound(TempColumns) - 1
                        If TempValuesNumber >= 0 Then
                            NewSubmittedRows = TempColumns(0)
                            NewEmptyRows     = TempColumns(1)
                        End If
                        SubmittedRows = CLng(NewSubmittedRows) + CLng(NewEmptyRows)

                        If TempValuesNumber > 1 And TempValuesNumber >= CachedColumnsNumber Then
                            ReDim NewCachedColumns(TempValuesNumber - CachedColumnsNumber + 1)
                            For i = 0 To TempValuesNumber - CachedColumnsNumber - 1
                                NewCachedColumns(i) = Replace(CCUnEscapeLOV(TempColumns(i + CachedColumnsNumber + 2)),"<!--semicolon-->",";")
                            Next
                        End If
                    End If
                Else
                    SubmittedRows = FormState
                End If
            End If
        End If

        GetCachedColumns = NewCachedColumns
    End Function
'End GetCachedColumns Method

'Fabricantes Show Method @2-7D957CFF
    Sub Show(Tpl)
        Dim StaticControls,RowControls

        If NOT Visible Then Exit Sub

        CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeSelect", Me)
        Set Recordset = DataSource.Open(Command)
        If Recordset.State = adStateOpen Then 
            EditMode = NOT Recordset.EOF 
        Else
            EditMode = False
        End If
        IsDSEmpty = NOT EditMode

        HTMLFormAction = FileName & "?" & CCAddParam(Request.ServerVariables("QUERY_STRING"), "ccsForm", "Fabricantes")
        Set TemplateBlock = Tpl.Block("EditableGrid " & ComponentName)
        TemplateBlock.Variable("HTMLFormName") = ComponentName
        TemplateBlock.Variable("Action") = HTMLFormAction
        TemplateBlock.Variable("HTMLFormProperties") = "action=""" & HTMLFormAction & """ method=""post"" " & "name=""" & ComponentName & """"
        TemplateBlock.Variable("HTMLFormEnctype") = "application/x-www-form-urlencoded"

        If DataSource.Errors.Count > 0 Then
            Errors.AddErrors(DataSource.Errors)
            DataSource.Errors.Clear
            With TemplateBlock.Block("Error")
                .Variable("Error") = Errors.ToString
                .Parse False
            End With
        End If

        Set StaticControls = CCCreateCollection(TemplateBlock, Null, ccsParseOverwrite, _
            Array(Navigator))
        Set RowControls = CCCreateCollection(TemplateBlock.Block("Row"), Null, ccsParseAccumulate, _
            Array(NomeFabricante, Link))

        CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeShow", Me)
        If NOT Visible Then Exit Sub

        RowControls.PreserveControlsVisible
        Dim i, j
        i = 1 : j = 0
        If EditMode AND ReadAllowed Then
            If Recordset.Errors.Count > 0 Then
                With TemplateBlock.Block("Error")
                    .Variable("Error") = Recordset.Errors.ToString
                    .Parse False
                End With
            ElseIf Not Recordset.EOF Then
                While Not Recordset.EoF AND (i-1) < PageSize
                    RowNumber = i
                    NomeFabricante.Value = Recordset.Fields("NomeFabricante")
                    Link.Value = Recordset.Fields("Link")
                    Link.Parameters = CCGetQueryString("QueryString", Array("ccsForm"))
                    Link.Page = ""

                    NomeFabricante.ExternalName = "NomeFabricante_" & CStr(i)
                    Link.ExternalName = "Link_" & CStr(i)

                    If j >= MaxCachedValues Then
                            MaxCachedValues = MaxCachedValues + 50
                            ReDim Preserve CachedColumns(MaxCachedValues*CachedColumnsNumber)
                    End If
                    CachedColumns(j * CachedColumnsNumber) = Recordset.Recordset.Fields("IdFabricante")
                    CachedValuesNumber = i

                    If IsFormSubmitted Then
                        If Len(ErrorMessages(i)) > 0 Then
                            With TemplateBlock.Block("Row").Block("RowError")
                                .Variable("Error") = ErrorMessages(i)
                                .Parse False
                            End With
                        Else
                            TemplateBlock.Block("Row").Block("RowError").Visible = False
                        End If
                    End If

                    CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeShowRow", Me)
                    Attributes.Show TemplateBlock.Block("Row"), "Fabricantes:"
                    RowControls.Show
                    i = i + 1: j = j + 1

                    Recordset.MoveNext
                Wend
            End If
            Attributes.Show TemplateBlock, "Fabricantes:"
            NomeFabricante.Value = Recordset.Fields("NomeFabricante")
            Link.Value = Recordset.Fields("Link")
            Link.Parameters = CCGetQueryString("QueryString", Array("ccsForm"))
            Link.Page = ""
        ElseIf Not EditMode Then
            Attributes.Show TemplateBlock, "Fabricantes:"
            TemplateBlock.Block("NoRecords").Parse ccsParseOverwrite
        End If

        SubmittedRows = i - 1
        TemplateBlock.Variable("FormScript") = GetFormScript(i - 1)
        TemplateBlock.Variable("FormState")  = GetFormState()

        If IsFormSubmitted Then
            If Errors.Count > 0 Or DataSource.Errors.Count > 0 Then
                Errors.addErrors DataSource.Errors
                With TemplateBlock.Block("Error")
                    .Variable("Error") = Errors.ToString
                    .Parse False
                End With
            End If
        End If

        Navigator.SetDataSource Recordset
        StaticControls.Show

    End Sub
'End Fabricantes Show Method

'Fabricantes PageSize Property Let @2-54E46DD6
    Public Property Let PageSize(NewValue)
        VarPageSize = NewValue
        DataSource.PageSize = NewValue
    End Property
'End Fabricantes PageSize Property Let

'Fabricantes PageSize Property Get @2-9AA1D1E9
    Public Property Get PageSize()
        PageSize = VarPageSize
    End Property
'End Fabricantes PageSize Property Get

End Class 'End Fabricantes Class @2-A61BA892

Class clsFabricantesDataSource 'FabricantesDataSource Class @2-6088E19C

'DataSource Variables @2-67877204
    Public Errors, Connection, Parameters, CCSEvents

    Public Recordset
    Public SQL, CountSQL, Order, Where, Orders, StaticOrder
    Public PageSize
    Public PageCount
    Public AbsolutePage
    Public Fields
    Dim WhereParameters
    Public AllParamsSet
    Public CachedColumns
    Public CachedColumnsNumber
    Public CurrentRow
    Public CmdExecution
    Public InsertOmitIfEmpty
    Public UpdateOmitIfEmpty

    Private CurrentOperation
    Private CCSEventResult

    ' Datasource fields
    Public NomeFabricante
    Public Link
'End DataSource Variables

'DataSource Class_Initialize Event @2-BEADEAAD
    Private Sub Class_Initialize()

        Set CCSEvents = CreateObject("Scripting.Dictionary")
        Set Fields = New clsFields
        Set Recordset = New clsDataSource
        Set Recordset.DataSource = Me
        Set Errors = New clsErrors
        Set Connection = Nothing
        AllParamsSet = True
        Set NomeFabricante = CCCreateField("NomeFabricante", "NomeFabricante", ccsText, Empty, Recordset)
        Set Link = CCCreateField("Link", "Link", ccsText, Empty, Recordset)
        Fields.AddFields Array(NomeFabricante, Link)

        SQL = "SELECT TOP {SqlParam_endRecord} *  " & vbLf & _
        "FROM Fabricantes {SQL_Where} {SQL_OrderBy}"
        CountSQL = "SELECT COUNT(*) " & vbLf & _
        "FROM Fabricantes"
        Where = ""
        Order = "NomeFabricante"
        StaticOrder = ""
    End Sub
'End DataSource Class_Initialize Event

'BuildTableWhere Method @2-1C84669B
    Public Sub BuildTableWhere()
        If CurrentRow > 0 Then
            Where = "IdFabricante=" & Connection.ToSQL(CachedColumns((CurrentRow - 1) * CachedColumnsNumber), ccsInteger)
        End If
    End Sub
'End BuildTableWhere Method

'Open Method @2-01AB0B49
    Function Open(Cmd)
        Errors.Clear
        CurrentRow = 0
        If Connection Is Nothing Then
            Set Open = New clsEmptyDataSource
            Exit Function
        End If
        Set Cmd.Connection = Connection
        Cmd.CommandOperation = cmdOpen
        Cmd.PageSize = PageSize
        Cmd.ActivePage = AbsolutePage
        Cmd.CommandType = dsTable
        Set WhereParameters = Nothing
        CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeBuildSelect", Me)
        Cmd.SQL = SQL
        Cmd.CountSQL = CountSQL
        Cmd.Where = Where
        Cmd.OrderBy = Order
        If(Len(StaticOrder)>0) Then
            If Len(Order)>0 Then Cmd.OrderBy = ", "+Cmd.OrderBy
            Cmd.OrderBy = StaticOrder + Cmd.OrderBy
        End If
        Cmd.Options("CLAUSE") = " TOP {SqlParam_endRecord}"
        Cmd.Options("SYNTAX") = "Top"
        Cmd.Options("PLACE") = "beforeFrom"
        CCSEventResult = CCRaiseEvent(CCSEvents, "BeforeExecuteSelect", Me)
        If Errors.Count = 0 And CCSEventResult Then _
            Set Recordset = Cmd.Exec(Errors)
        CCSEventResult = CCRaiseEvent(CCSEvents, "AfterExecuteSelect", Me)
        Set Recordset.FieldsCollection = Fields
        Set Open = Recordset
    End Function
'End Open Method

'DataSource Class_Terminate Event @2-41B4B08D
    Private Sub Class_Terminate()
        If Recordset.State = adStateOpen Then _
            Recordset.Close
        Set Recordset = Nothing
        Set Parameters = Nothing
        Set Errors = Nothing
    End Sub
'End DataSource Class_Terminate Event

End Class 'End FabricantesDataSource Class @2-A61BA892

'Include Page Implementation @8-FD86017A
%>
<!-- #INCLUDE VIRTUAL="/fepace/Header.asp" -->
<%
'End Include Page Implementation

'Include Page Implementation @7-C597799D
%>
<!-- #INCLUDE VIRTUAL="/fepace/Footer.asp" -->
<%
'End Include Page Implementation

%>
